package com.newthread.jdp.model;

import java.util.Date;
import java.util.List;

import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;

@Entity
public class Message {
	private int id;
	private int messageType;

	public int getMessageType() {
		return messageType;
	}

	public void setMessageType(int messageType) {
		this.messageType = messageType;
	}

	private String title;
	private String content;
	private Date time;
	private MessageState messageState;
	private UserInfo pushUser;
	private List<UserInfo> reciveUsers;
	private List<Message> messages;
	private Message(){
		
	}
	public Message(UserInfo pushUser, List<UserInfo> reciveUsers,
			String content, MessageState messageState, int messageType) {
		this.pushUser = pushUser;
		this.reciveUsers = reciveUsers;
		this.content = content;
		this.messageState = messageState;
		this.messageType = messageType;
	}

	public Message(UserInfo pushUser, List<UserInfo> reciveUsers, String title,
			String content, MessageState messageState, int messageType) {
		this(pushUser, reciveUsers, content, messageState, messageType);
		this.title = title;
	}

	@Id
	@GeneratedValue
	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	@ManyToOne
	@JoinColumn(name = "pushUserId")
	public UserInfo getPushUser() {
		return pushUser;
	}

	public void setPushUser(UserInfo pushUser) {
		this.pushUser = pushUser;
	}

	public Date getTime() {
		return time;
	}

	public void setTime(Date time) {
		this.time = time;
	}

	@Enumerated(EnumType.STRING)
	public MessageState getMessageState() {
		return messageState;
	}

	public void setMessageState(MessageState messageState) {
		this.messageState = messageState;
	}

	@ManyToMany(mappedBy = "receveMessage")
	public List<UserInfo> getReciveUsers() {
		return reciveUsers;
	}

	public void setReciveUsers(List<UserInfo> reciveUsers) {
		this.reciveUsers = reciveUsers;
	}

	@OneToMany(fetch=FetchType.EAGER)
	@JoinTable(name = "message_replyMessage", joinColumns = { @JoinColumn(name = "message_id") }, inverseJoinColumns = { @JoinColumn(name = "replyMessage_id") })
	public List<Message> getMessages() {
		return messages;
	}

	public void setMessages(List<Message> messages) {
		this.messages = messages;
	}

}
